package com.example.lx6_1.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil.ItemCallback
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.alibaba.android.arouter.launcher.ARouter
import com.example.base.entity.AreaEntityItem
import com.example.lx6_1.R
import com.example.lx6_1.databinding.ItemParkBinding

class AreaAdapter : PagingDataAdapter<AreaEntityItem, AreaAdapter.AreaViewHolder>(diff) {

    companion object{
        val diff = object : ItemCallback<AreaEntityItem>() {
            override fun areItemsTheSame(
                oldItem: AreaEntityItem,
                newItem: AreaEntityItem
            ): Boolean {
                return oldItem == newItem
            }

            override fun areContentsTheSame(
                oldItem: AreaEntityItem,
                newItem: AreaEntityItem
            ): Boolean {
                return oldItem.id == newItem.id
            }

        }
    }


    class AreaViewHolder(view:View) : ViewHolder(view) {
        val binding = DataBindingUtil.bind<ItemParkBinding>(view)
    }

    override fun onBindViewHolder(holder: AreaViewHolder, position: Int) {
        holder.binding?.park = getItem(position)
        holder.itemView.setOnClickListener {
            ARouter.getInstance().build("/app/VRActivity").navigation()
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AreaViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_park, parent, false)
        return AreaViewHolder(view)
    }


}